package org.mysfit.ctp4j.infra.utils;

import org.mysfit.ctp4j.infra.enums.OSInfoEnum;

/**
 * 操作系统信息判断工具类
 * 
 * @author long.gf
 *
 */
public class OSInfoUtils {
	
	private static String OS = System.getProperty("os.name").toLowerCase();

	public static boolean isLinux() {
		return OS.indexOf("linux") >= 0;
	}

	public static boolean isMacOS() {
		return OS.indexOf("mac") >= 0 && OS.indexOf("os") > 0 && OS.indexOf("x") < 0;
	}

	public static boolean isWindows() {
		return OS.indexOf("windows") >= 0;
	}

	public static OSInfoEnum getOSInfo() {
		if (isLinux()) {
			return OSInfoEnum.Linux;
		} else if (isMacOS()) {
			return OSInfoEnum.MacOS;
		} else if (isWindows()) {
			return OSInfoEnum.Windows;
		} else {
			return OSInfoEnum.Others;
		}
	}
	
	public static String parseToOssObjectName(String filePath , String ossGroup, String fileDir) {
		String objectName = "";
		if(isWindows()) {
			int index = fileDir.length();
			objectName = filePath.substring(index).replaceAll("\\\\", "/");
		}else {
			objectName = filePath.replaceFirst(fileDir, "");
		}
		if(objectName.startsWith("/")) {
			return ossGroup + objectName;
		}else {
			return ossGroup + "/" + objectName;
		}
	}

}
